<template>
	<!-- 商品显示 组件 -->
	<view class="goods_col"
		:style="{marginTop: `${newData.pageUpSpacing}rpx`,marginBottom: `${newData.pageDownSpacing}rpx`}">
		<view class="flex-row-center" :style="{paddingTop: `${newData.titleUpSpacing}rpx`,paddingBottom: `${newData.titleDownSpacing}rpx`}">
			<view class="text-bold" :style="{color: `${newData.titleColor}`,fontSize:`${newData.titleSize}rpx`}">
				<text class="cuIcon-move "></text>
				<text style="margin:0 10rpx">{{newData.title}}</text>
				<text class="cuIcon-move"></text>
			</view>
		</view>
		<view>
			<goods-card :goodsList="newData.goodsList"></goods-card>
		</view>
	</view>
</template>

<script>
	const app = getApp();
	import api from '@/utils/api'
	import goodsCard from "./goods-card.vue";

	export default {
		components: {
			goodsCard,
		},
		props: {
			value: {
				type: Object,
				default: function() {
					return {
						showType: 'row',
						pageSpacing: 0,
						goodsList: []
					}
				}
			}
		},
		data() {
			return {
				theme: app.globalData.theme, //全局颜色变量
				newData: this.value,
			};
		},
		mounted() {
			this.getgoodsList()
		},
		methods: {
			jumpPage(page) {
				if (page) {
					uni.navigateTo({
						url: page
					});
				}
			},
			// 获取活动商品
			getgoodsList() {
				if (this.newData.goodsList && this.newData.goodsList.length > 0) {
					let goodsids = []
					this.newData.goodsList.forEach(v => {
						goodsids.push(v.id)
					})
					const goodsData = {
						ids: goodsids.toString()
					}
					api.getHomepageGoods(goodsData).then(res => {
						let data = res.data
						if (data.length > 0) {
							this.newData.goodsList = data.filter(v => {
								return v.shelf == '1'
							})
						} else {
							this.newData.goodsList = []
						}

					})
				}
			}
		}
	}
</script>

<style scoped>
	.goods_col {
		background-color: #fff;
		margin: 0 20rpx;
		border-radius: 10rpx;
	}
</style>